<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<script type="text/javascript" src="js/jquery.itextclear.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $('input[type=text], input[type=password], input[type=url], input[type=email], input[type=number], textarea', '.form').iTextClear();
    });
</script>
<!-- jQplot CSS -->

<link rel="stylesheet" media="screen" href="CSS/Tree.css"/>
<!-- jQplot CSS END -->

<!-- DATATABLES CSS -->
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css"/>
<script type="text/javascript" src="lib/datatables/js/jquery.dataTables.js"></script>
<!-- DATATABLES CSS END -->

<h1 class="page-title">合同人员设置 - ${person == null ? "添加" : "修改"}</h1>

<div class="container_12 clearfix leading">

    <%@ include file="/WEB-INF/pages/common/common_tree.jsp" %>

    <div class="side grid_8 leading">
        <form class="form has-validation" name="post_form" id="post_form">
            <div class="clear"></div>

            <div class="clearfix">
                <label for="duty_sel" class="form-label">适用职务 <em>*</em></label>
                <div class="form-input">
                    <select name="person.duty.id" id="duty_sel">
                    </select>
                </div>

                <div class="clearfix">
                    <label for="version_sel" class="form-label">合同类别 <em>*</em></label>
                    <div class="form-input">
                        <select id="version_sel" name="person.contractVersion.id" style="opacity: 0;">
                        </select>
                    </div>
                </div>

                <div class="clearfix"></div>

            </div>
            <div class="form-action clearfix">
                <s:if test="#request.person != null and #request.person.id != null">
                <input type="hidden" name="person.id" value="${person.id}"/>
                </s:if>
                <button class="button" type="button" onclick="checkForm()">${person == null ? "添加" : "修改"}</button>
                <button class="button" type="button" onclick="resetForm()">重置</button>
                <a class="button" href="#contract/personnel.xhtml"><span style="background:url(${ctx}/images/img/arrow_undo.png)" class="icon">&nbsp;</span>返回</a>
            </div>
        </form>
    </div>
</div>


<div class="clear"></div>

<script type="text/javascript" src="js/Tree.js"></script>
<script type="text/javascript" src="${ctx}/js/global_util.js"></script>
<script type="text/javascript">
    $(function(){
        $("#duty_sel").val("${version.companyName}");
        $("#duty_sel").val("${version.contractTemplate}");
    });

    function findDuty(organizationId) {
        findVersions(organizationId);

        $.getJSON("${ctx}/ajax/duty-list.xhtml?organizationId=" + organizationId, function(duties) {
            $("#uniform-duty_sel span:first").text("");//清除上次选择的职务
            var selObj = $("#duty_sel");
            selObj.html("");
            if (duties != null && duties.length != 0) {
                $.each(duties, function(i, duty) {
                    if(i == 0){
                        $("#uniform-duty_sel span:first").html(duty.dutyName);//设置本次选择的职务
                    }
                    selObj.append("<option value='" + duty.id + "'>" + duty.dutyName + "</option>")
                });
                //selObj.get(0).selectedIndex = 1;
            }
        });
    }

    function findVersions(organizationId) {
        $.getJSON("${ctx}/ajax/contact-version-list.xhtml?organizationId=" + organizationId, function(versions) {
            $("#uniform-version_sel span:first").text("");//清除上次选择的类别
            var selObj = $("#version_sel");
            selObj.html("");
            if (versions != null && versions.length != 0) {
                $.each(versions, function(i, version) {
                    if(i == 0){
                        $("#uniform-version_sel span:first").html(version.contractName);//设置本次选择的合同类别
                    }
                    selObj.append("<option value='" + version.id + "'>" + version.contractName + "</option>")
                });
            }
        });
    }

    function checkForm() {
        if (checkNull($("#duty_sel").attr("value"))) {
            alert("请选择合同");
            return false;
        }
        if (checkNull($("#version_sel").attr("value"))) {
            alert("请选择合同版本");
            return false;
        }

        var url = "${ctx}/contract/personnel_save.xhtml";
        $.ajax(url, {
            type: "POST",
            data: $("#post_form").serialize(),
            dataType:"html",
            cache:false,
            success:function(a) {
                return pageDownloaded(a, url)
            },
            complete:function() {
            }
        });
    }
    function resetForm() {
        $("#duty_sel").attr("value", "");
        $("#version_sel").attr("value", "");
    }
</script>
    